﻿namespace Resharper.Abstractions.CodeDom.Expressions.InvocationExpressions
{
  using System;
  using JetBrains.Annotations;
  using JetBrains.ReSharper.Psi;
  using JetBrains.ReSharper.Psi.CSharp.Tree;
  using Resharper.Abstractions.Actions;

  /// <summary>Defines the <see cref="InvocationExpressionExtensions"/> class.</summary>
  public static class ArgumentExtensions
  {
    #region Public Methods

    /// <summary>Gets the selected literal expression.</summary>
    /// <param name="factory">The factory.</param>
    /// <param name="code">The code.</param>
    /// <returns>Returns the selected literal expression.</returns>
    [NotNull]
    public static Argument CreateArgument([NotNull] this Factory factory, string code)
    {
      if (factory == null)
      {
        throw new ArgumentNullException("factory");
      }

      var expression = factory.CreateExpression(code);

      var arg = factory.InternalFactory.CreateArgument(ParameterKind.VALUE, (ICSharpExpression)expression.InternalExpression);

      return new Argument(arg);
    }

    #endregion
  }
}